// 
// SoapTrace.Net - A soap message monitoring utility. 
// 
// Copyright (C) 2004 Matthew Ward
// 
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
// 
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
// 
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
// 
// Matthew Ward (mrward@users.sourceforge.net)
// 

using System;
using NUnit.Framework;
using SoapTrace.Core.Communication;

namespace SoapTrace.Tests
{
	/// <summary>
	/// Test fixture for the <see cref="SoapRequestAndResponse"/>
	/// class.
	/// </summary>
	[ TestFixture ]
	public class SoapRequestAndResponseTestFixture
	{
		/// <summary>
		/// Tests that the <see cref="SoapRequestAndResponse"/>
		/// class returns an empty string for properties such
		/// as <see cref="SoapRequestAndResponse.WebService"/>
		/// if it does not contain a <see cref="SoapRequest"/>
		/// object.</summary>
		/// <remarks>
		/// <para>The main problem with the <see cref="SoapRequestAndResponse"/>
		/// class is that it takes a lot of information from
		/// the <see cref="SoapRequest"/> class but was not handling
		/// the case where the <see cref="SoapRequest"/> did not 
		/// exist.  Whilst a <see cref="SoapRequestAndResponse"/>
		/// class without a <see cref="SoapRequest"/> is pretty useless
		/// ensuring that it handles the problem without throwing
		/// an exception makes it robust.</para>
		/// <para>This particular problem was highlighted because the
		/// SoapTrace application attempts to display a Soap request and
		/// response if only the response was received.</para> 
		/// </remarks>
		[ Test ]
		public void NoRequest( )
		{
			ClientId Id = new ClientId( );
			SoapRequestAndResponse RequestAndResponse = 
				new SoapRequestAndResponse( Id );

			Assert.AreEqual( null, RequestAndResponse.Request, "Null request expected." );
			Assert.AreEqual( null, RequestAndResponse.Response, "Null response expected." );
			Assert.AreEqual( new DateTime( 2000, 1, 1 ), RequestAndResponse.TimeReceived, "Default time received is incorrect." );
			Assert.AreEqual( Id, RequestAndResponse.ClientId, "Client id mismatch." );
			Assert.AreEqual( "", RequestAndResponse.Uri, "No uri should be set." );
			Assert.AreEqual( "", RequestAndResponse.WebMethod, "No web operation should be set." );
			Assert.AreEqual( "", RequestAndResponse.WebService, "No web service should be set." );
		}
	}
}
